package cn.rdq.iknessplatform.service.impl;

import cn.rdq.api.po.Views;
import cn.rdq.dao.ViewsMapper;
import cn.rdq.iknessplatform.service.ViewsService;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class ViewsServiceImpl extends ServiceImpl<ViewsMapper, Views> implements ViewsService {


    @Override
    public void saveViews(Views views) {
        Date date = views.getDateHistory();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = dateFormat.format(date);
        UpdateWrapper<Views> wrapper = new UpdateWrapper<>();
        wrapper.eq("date_history", format);
        wrapper.set("views", views.getViews());
        wrapper.set("date_history", format);
        saveOrUpdate(views, wrapper);
    }
}
